﻿using MediatR;
using SystemHYS.API.Application.command.RawmaterialtestingCommand;
using SystemHYS.Domian;
using SystemHYS.Infrstructre.Interface;
namespace SystemHYS.API.Application.commandler.RawmaterialtestingCommandler
{
    public class RawmaterialtestingShowCommandler : IRequestHandler<RawmaterialtestingShowCommand, List<Rawmaterialtesting>>
    {
        IRawmaterialtestingRepository rawmaterialtestingRepository;
        public RawmaterialtestingShowCommandler(IRawmaterialtestingRepository rawmaterialtestingRepository)
        {
            this.rawmaterialtestingRepository = rawmaterialtestingRepository;
        }

        public async Task<List<Rawmaterialtesting>> Handle(RawmaterialtestingShowCommand request, CancellationToken cancellationToken)
        {
            var list =from a in await rawmaterialtestingRepository.GetAllAsnc() where a.IsDel==false select a;
            if (request.ingredientNumber != null)
            {
                list = list.Where(x => x.ingredientNumber.Contains(request.ingredientNumber));
            }
            if (request.qualityNumber != null)
            {
                list = list.Where(x => x.qualityNumber.Contains(request.qualityNumber));
            }
            if(request.state != null)
            {
                list = list.Where(x => x.state==request.state);
            }
            return list.ToList();
        }
    }
}
